unit Con_CST;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Formulario_Padrao_Consulta, TFlatButtonUnit, StdCtrls, Buttons,
  ExtCtrls, DB, Grids, DBGrids, dbtables;

type
  TfrmCon_CST = class(TFrmConsulta)
    edCodigo: TEdit;
    Label1: TLabel;
    DBGrid1: TDBGrid;
    DS: TDataSource;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure edCodigoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    codCST: string;
    codUF: string;
  end;

var
  frmCon_CST: TfrmCon_CST;
  tq: TQuery;

implementation

uses clsCST, Dm;

var
  CST: TCST;

{$R *.dfm}

procedure TfrmCon_CST.FormCreate(Sender: TObject);
begin
  inherited;
  CST := TCST.Create;
  tq := TQuery.Create(DmInt);
  tq.DatabaseName := DmInt.Db.DatabaseName;
end;

procedure TfrmCon_CST.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  CST.Free;
  tq.Close;
  tq.Free;
end;

procedure TfrmCon_CST.FormActivate(Sender: TObject);
begin
  inherited;
  edCodigo.Clear;
  FazConsulta;
  edCodigo.SetFocus;
end;

procedure TfrmCon_CST.FazConsulta;
begin
  CST.ConsultaporCST(edCodigo.Text, tq);
  DS.DataSet := tq;
  tq.First;

end;

procedure TfrmCon_CST.BtnFecharClick(Sender: TObject);
begin
  inherited;
  codCST := tq.FieldByName('CST_Codigo').AsString;
  codUF:= tq.FieldByName('est_sigla').AsString;
end;

procedure TfrmCon_CST.edCodigoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
 if key = 12 then
   FazConsulta;
end;

procedure TfrmCon_CST.DBGrid1DblClick(Sender: TObject);
begin
  inherited;
 BtnFecharClick(sender);
end;

end.

